<!-- 蓝色登录页面2 -->
<template>
	<view>
		<view class="img-a">
			<view class="t-b">
				<view>您好，</view>
				<view>欢迎使用消防单位智能管理系统</view>
			</view>
		</view>
		<view class="login-view" style="">
			<view class="t-login">
				<form class="cl">
					<view class="t-a">
						<text class="txt">账号</text>
						<input type="text" name="phone" placeholder="请输入您的账号" v-model="phone" />
					</view>
					<view class="t-a">
						<text class="txt">密码</text>
						<input type="password" name="code" maxlength="18" placeholder="请输入您的密码" v-model="pwd" />
					</view>
					<button @click="login()">登 录</button>
					<view class="reg">
						<view class="btn60" style="display:flex;align-items:center">
							<view>
								<u-radio-group v-model="iagree" placement="row" @change="iagree = !iagree">
									<u-radio label=""></u-radio>
								</u-radio-group>
							</view>
							<view class="iagree" @click="toTerms">
								<rich-text>服务条款及隐私协议</rich-text>
							</view>
						</view>
					</view>
				</form>

				<!-- <view class="t-f"><text>—————— 第三方账号登录 ——————</text></view>
				<view class="t-e cl">
					<view class="t-g" @tap="wxLogin()"><image src="@/static/wx.png"></image></view>
					<view class="t-g" @tap="zfbLogin()"><image src="@/static/qq.png"></image></view>
				</view> -->
			</view>
		</view>
	</view>
</template>
<script>
	import http from '@/common/api/index.js';
	import { BASE_IP } from '@/common/http/url.js';
	import { useLoginStore } from '@/store/login.js';
	export default {
		data() {
			return {
				// #ifdef MP-WEIXIN
				// phone: '18888888888', //手机号码
				// pwd: '1234', //密码
				phone: '', //手机号码
				pwd: '', //密码
				// #endif
				iagree: true
			};
		},
		onLoad() {
			// #ifdef MP-WEIXIN || H5
			// this.login();
			// #endif
		},
		methods: {
			//当前登录按钮操作
			login() {
				console.log("11111")
				var that = this;
				let num = that.phone;
				let pwd = that.pwd;
				if (!that.iagree) {
					uni.showToast({
						title: '请同意条款',
						icon: 'error',
						duration: 2000
					});
					return;
				}
				if (!num) {
					uni.showToast({
						title: '请输入您的账号',
						icon: 'error',
						duration: 2000
					});
					return;
				}
				if (!pwd) {
					uni.showToast({
						title: '请输入您的密码',
						icon: 'error',
						duration: 2000
					});
					return;
				}

				let store = useLoginStore();

				let list = {
					userName: num,
					password: pwd
				};
				let url = BASE_IP + 'pc/user/login';
				uni.request({
					url: url,
					data: list,
					method: 'POST',
					success: (res) => {
						console.log(1111, res)
						if (res.statusCode == 200) {
							console.log('登录请求成功：', res.data);
							if (res.data.code == 500) {
								uni.showModal({
									title: "提示",
									content: res.data.msg,
									showCancel: false
								})
								return
							}
							if (res.data.code != 200) {
								uni.showModal({
									title: "提示",
									content: res.data.errors,
									showCancel: false
								})
								return
							}
							store.user = res.data.msg;
							uni.setStorageSync('user', res.data.msg);
							if (store.user != '' || store.user != null) {
								uni.showToast({
									title: '登录成功',
									icon: 'none',
									duration: 3000
								});
								uni.switchTab({
									url: '/pages/index/index'
								});

							}
						} else {
							uni.showToast({
								title: '服务器错误',
								icon: 'error'
							});
						}
						if (res.statusCode == 500) {
							uni.showToast({
								title: '账号或密码错误',
								icon: 'error'
							});
						}

						if (res.statusCode == 404) {
							uni.showToast({
								title: '服务器错误',
								icon: 'error'
							});
						}
					},
					fail: (res) => {

						uni.showToast({
							title: '服务器错误',
							icon: 'error',
							duration: 2000
						});
						return;
					},


				});
			},
			//注册按钮点击
			reg() {
				uni.showToast({ title: '注册跳转', icon: 'none' });
			},
			//等三方微信登录
			wxLogin() {
				uni.showToast({ title: '微信登录', icon: 'none' });
			},
			//第三方支付宝登录
			zfbLogin() {
				uni.showToast({ title: '支付宝登录', icon: 'none' });
			},
			toTerms() {
				// console.log(this.iagree)
				uni.navigateTo({
					url: '/pages/termsService/termsService'
				});
			}
		}
	};
</script>
<style>
	.txt {
		font-size: 32rpx;
		font-weight: bold;
		color: #333333;
	}

	.img-a {
		width: 100%;
		height: 450rpx;
		background: #2796f2;
	}

	.reg {
		font-size: 28rpx;
		color: #fff;
		height: 90rpx;
		line-height: 90rpx;
		/* border-radius: 50rpx; */
		font-weight: bold;
		/* background: #f5f6fa; */
		color: #000000;
		text-align: center;
		margin-top: 30rpx;
	}

	.login-view {
		width: 100%;
		position: relative;
		margin-top: -120rpx;
		background-color: #ffffff;
		border-radius: 8% 8% 0% 0;
	}

	.t-login {
		width: 600rpx;
		margin: 0 auto;
		font-size: 28rpx;
		padding-top: 80rpx;
	}

	.t-login button {
		font-size: 28rpx;
		background: #2796f2;
		color: #fff;
		height: 90rpx;
		line-height: 90rpx;
		border-radius: 50rpx;
		font-weight: bold;
	}

	.t-login input {
		height: 90rpx;
		line-height: 90rpx;
		margin-bottom: 50rpx;
		border-bottom: 1px solid #e9e9e9;
		font-size: 28rpx;
	}

	.t-login .t-a {
		position: relative;
	}

	.t-b {
		text-align: left;
		font-size: 42rpx;
		color: #ffffff;
		padding: 130rpx 0 0 70rpx;
		font-weight: bold;
		line-height: 70rpx;
	}

	.t-login .t-c {
		position: absolute;
		right: 22rpx;
		top: 22rpx;
		background: #5677fc;
		color: #fff;
		font-size: 24rpx;
		border-radius: 50rpx;
		height: 50rpx;
		line-height: 50rpx;
		padding: 0 25rpx;
	}

	.t-login .t-d {
		text-align: center;
		color: #999;
		margin: 80rpx 0;
	}

	.t-login .t-e {
		text-align: center;
		width: 250rpx;
		margin: 80rpx auto 0;
	}

	.t-login .t-g {
		float: left;
		width: 50%;
	}

	.t-login .t-e image {
		width: 50rpx;
		height: 50rpx;
	}

	.t-login .t-f {
		text-align: center;
		margin: 150rpx 0 0 0;
		color: #666;
	}

	.t-login .t-f text {
		margin-left: 20rpx;
		color: #aaaaaa;
		font-size: 27rpx;
	}

	.t-login .uni-input-placeholder {
		color: #aeaeae;
	}

	.cl {
		zoom: 1;
	}

	.cl:after {
		clear: both;
		display: block;
		visibility: hidden;
		height: 0;
		content: '\20';
	}

	.btn60 {
		width: 70%;
		margin: 10rpx auto;
	}

	.iagree {
		color: #49a0ff;
		font-size: 14px;
		text-decoration: underline;
	}

	.iagree:active {
		opacity: 0.5;
	}
</style>